package com.aspose.cells.a.d.b;

import com.aspose.cells.a.e.zf;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;

public class zb {
   public static RenderedImage a(Image var0, ImageObserver var1, Color var2) {
      if (var2 == null && var0 instanceof RenderedImage) {
         return (RenderedImage)var0;
      } else {
         BufferedImage var3 = new BufferedImage(var0.getWidth(var1), var0.getHeight(var1), var2 == null ? 2 : 1);
         Graphics var4 = var3.getGraphics();
         if (var2 == null) {
            var4.drawImage(var0, 0, 0, var1);
         } else {
            var4.drawImage(var0, 0, 0, var2, var1);
         }

         return var3;
      }
   }

   public static byte[] a(RenderedImage var0, Color var1, String var2, int var3) {
      if (var3 < 1) {
         var3 = 1;
      }

      Raster var4 = var0.getData();
      int var5 = var0.getWidth();
      int var6 = var0.getHeight();
      boolean var7 = var2.charAt(0) == '*';
      if (var7) {
         var2 = var2.substring(1);
      }

      int var8 = var2.length();
      int var9 = var5 * var6 * var8;
      var9 += var5 % var3 * var6;
      int var10 = 0;
      byte[] var11 = new byte[var9];
      ColorModel var12 = var0.getColorModel();

      for(int var13 = 0; var13 < var6; ++var13) {
         int var14;
         for(var14 = 0; var14 < var5; ++var14) {
            int var15 = var12.getRGB(var4.getDataElements(var14, var13, (Object)null));
            int var16 = var15 >> 24 & 255;
            int var17 = var15 >> 16 & 255;
            int var18 = var15 >> 8 & 255;
            int var19 = var15 >> 0 & 255;
            if (var7 && var16 < 255) {
               if (var1 == null) {
                  var1 = Color.BLACK;
               }

               double var20 = (double)var16 / 255.0D;
               var17 = (int)(var20 * (double)var17 + (1.0D - var20) * (double)var1.getRed());
               var18 = (int)(var20 * (double)var18 + (1.0D - var20) * (double)var1.getGreen());
               var19 = (int)(var20 * (double)var19 + (1.0D - var20) * (double)var1.getBlue());
            }

            for(int var22 = 0; var22 < var2.length(); ++var22) {
               switch(var2.charAt(var22)) {
               case 'A':
               case 'a':
                  var11[var10] = (byte)var16;
                  break;
               case 'B':
               case 'b':
                  var11[var10] = (byte)var19;
                  break;
               case 'G':
               case 'g':
                  var11[var10] = (byte)var18;
                  break;
               case 'R':
               case 'r':
                  var11[var10] = (byte)var17;
                  break;
               default:
                  zf.a(zb.class.getClass() + ": Invalid code in '" + var2 + "'");
               }

               ++var10;
            }
         }

         for(var14 = 0; var14 < var5 % var3; ++var14) {
            var11[var10] = 0;
            ++var10;
         }
      }

      return var11;
   }
}
